package com.epsilon.commons.util.map.viewers;

import java.util.List;

import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;

import com.epsilon.commons.util.map.model.IMapeable;

public class IMapeableComboConfig implements IStructuredContentProvider, ILabelProvider {

	private boolean	mostrarCodigo	= true;

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged( Viewer arg0, Object arg1, Object arg2 ) {
	}

	@Override
	public void addListener( ILabelProviderListener arg0 ) {
	}

	@Override
	public boolean isLabelProperty( Object arg0, String arg1 ) {
		return false;
	}

	@Override
	public void removeListener( ILabelProviderListener arg0 ) {
	}

	@Override
	@SuppressWarnings( "rawtypes" )
	public Object [] getElements( Object arg0 ) {
		List listaDeIMapeables = (List)arg0;
		return listaDeIMapeables.toArray();
	}

	public void setMostrarCodigo( boolean mostrar ) {
		mostrarCodigo = mostrar;
	}

	@Override
	public Image getImage( Object arg0 ) {
		return null;
	}

	@Override
	public String getText( Object element ) {

		IMapeable mapeable = (IMapeable)element;

		if( mostrarCodigo ) {
			return (mapeable.getCodigo() != null ? mapeable.getCodigo() : "N.A.") + " - "
					+ (mapeable.getDescripcion() != null ? mapeable.getDescripcion() : "N.A.");
		} else
			return (mapeable.getDescripcion() != null ? mapeable.getDescripcion() : "N.A.");
	}
}